import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        // 电梯动画 t有 f没
        // 标签栏 一层开关
        Tabbar_TB: false,
        //小播放器 一层开关
        SmallPlay_TB1: false,
        //小播放器 二层开关
        SmallPlay_TB2: false,

        // 我的设置(弹出层) 弹出开关 t弹出f收起
        showMySettings: false,

        // Play大组件 显示开关
        PlayPage: false,

        // 白名单
        nameData: ['Vip', 'SingerDetails', 'SongSheet'],

        mainRouter: "Recommend"
    },
    mutations: {
        //我的设置(弹出) ==> 小播放器 0层  标签栏0层
        MySettings_TB_Fn(state, tf) {
            // console.log("tf===>", tf);
            state.Tabbar_TB = !tf;
            state.SmallPlay_TB2 = !tf;
            state.showMySettings = tf;
        },
        // 登录 ==> 小播放器 0层  标签栏0层
        LogOn_TB_Fn(state) {
            state.Tabbar_TB = false;
            state.SmallPlay_TB2 = false;
        },

        //VIP ==> 小播放器 1层  标签栏0层
        VIP_TB_Fn(state, tf) {
            state.SmallPlay_TB1 = tf;
            state.SmallPlay_TB2 = !tf;
            state.showMySettings = false;
        },

        //Main ==> 小播放器 2层  标签栏1层
        Main_TB_Fn(state, tf) {
            state.Tabbar_TB = tf;
            state.SmallPlay_TB1 = !tf;
            state.SmallPlay_TB2 = tf;
        },

        //Play ==> 小播放器 1层  标签栏0层
        Play_TB_Fn(state, params) {
            if (state.nameData.indexOf(params.name) === -1) {
                state.SmallPlay_TB1 = params.tf;
                state.SmallPlay_TB2 = !params.tf;
            }
            state.Tabbar_TB = !params.tf;
            state.PlayPage = params.tf;
        },

        changemainRouter(state, Router) {
            state.mainRouter = Router;
            console.log("🚀 ==> changemainRouter ==> state.mainRouter", state.mainRouter);
        }
    },
    actions: {
    },
    modules: {

        //控制 音频
        controlAudio: {
            namespaced: true,
            state: {
                //初始化跳过播放
                vuexInit: true,

                // 是否获取新的歌曲数据
                obtainNewData_YN: false,
                //歌曲列表
                songsData: [
                    // {
                    //     url:null,
                    //     id:null,
                    //     cover:null,
                    //     songTitle:null,
                    //     singer:null,
                    //     lyric:null,
                    //     lyricYesNo:null
                    // }
                ],
                //当前播放歌曲的下标
                songIndex: 0,


                // t播放  f暂停
                playSuspend: false,
                // 模式 ==> 0顺序 1随机 2单曲循环
                pattern: 2,
                // 当前音频路径
                url: require('../assets/Daft Punk - Something About Us.mp3'),
                // 当前音频id
                id: 1,
                // 封面
                cover: require("../assets/tx.png"),
                // 歌名
                songTitle: 'Something About Us',
                // 歌手
                singer: 'Daft Punk',
                // 音频总时长
                durationText: '',
                // 音频当前播放时间
                currentTimeText: '',
                // 歌词
                lyric: [{ text: '作曲 : Daft Punk' }, { text: '纯音乐，请欣赏' }],
                // 歌词下标
                lyric_Index: 0,
                // 没有时间提示效果  t无 f有
                lyricYesNo: null,
            },
            getters: {},
            mutations: {
                // 播放暂停 切换/控制
                playSuspend_Switch(state) {
                    state.playSuspend = !state.playSuspend;
                    console.log("🚀vuex ==>  t播放  f暂停 ==>", state.playSuspend);
                },

                //修改音频路径
                changeAudioUrl(state, url) {
                    console.log("🚀 ==> changeAudioUrl ==> url", url);
                    state.url = url;
                    state.songIndex = 0;
                    state.playSuspend = true;

                    if (state.vuexInit) {
                        state.vuexInit = false;
                    }
                },
                // 修改音频 封面 歌名 歌手
                changeAudio_Cover_SongTitle_Singer(state, params) {
                    state.cover = params.cover; // 封面
                    state.songTitle = params.songTitle; // 歌名
                    state.singer = params.singer;// 歌手
                },
                //添加歌曲到歌曲列表
                addSongsData(state, obj) {
                    // 过滤相同歌曲
                    state.songsData = state.songsData.filter(function (v, i) {
                        if (obj.id !== v.id) {
                            return true
                        } else {
                            return false;
                        }
                    })

                    state.songsData.unshift(obj);
                    console.log("🚀 ==> addSongsData ==>  state.songsData", state.songsData);
                },
                removeSongsData(state, songIndex) {
                    state.songsData.splice(songIndex, 1);
                    console.log("🚀 ==> removeSongsData ==> state.songsData", state.songsData);
                },

                // 在音乐列表中 选中要播放的歌
                SelectPlay(state, songIndex) {
                    state.songIndex = songIndex;
                    console.log("🚀 ==> SelectPlay ==> songIndex", songIndex);

                    state.url = state.songsData[songIndex].url;
                    state.id = state.songsData[songIndex].id;
                    state.cover = state.songsData[songIndex].cover;
                    state.songTitle = state.songsData[songIndex].songTitle;
                    state.singer = state.songsData[songIndex].singer;
                    state.lyric = state.songsData[songIndex].lyric;
                    state.lyricYesNo = state.songsData[songIndex].lyricYesNo;
                    console.log("🚀 ==> SelectPlay ==> state", state);
                },


                //动态修改state的属性
                changeStateProperty(state, params) {
                    //params.key: state的属性名
                    //params.value: 修改的值
                    if (params.key !== 'currentTimeText') {
                        if (params.key !== 'lyric_Index') {
                            console.log('controlAudio ==> params ==> ', params);
                        }
                    }
                    state[params.key] = params.value;
                },
            },
            actions: {},
            modules: {},
        },


        // 控制用户
        Account: {
            namespaced: true,
            state: {
                // 用户id
                uid: null,
                // 头像
                avatarUrl: "",
                // 昵称
                nickname: "请登录",
                // 介绍
                signature: '请登录',
                // 等级
                level: 0,
            },
            getters: {},
            mutations: {   //动态修改state的属性
                changeStateProperty(state, params) {
                    //params.key: state的属性名
                    //params.value: 修改的值

                    console.log('Account ==> params ==> ', params);
                    state[params.key] = params.value;
                },
            },
            actions: {},
            modules: {},
        }
    }
})
